package com.excesys.exsecs.eco.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.eco.entity.StrategyMain;
import com.excesys.exsecs.eco.entity.StrategyVariable;
import com.excesys.exsecs.eco.mapper.StrategyVariableMapper;
import com.excesys.exsecs.eco.service.StrategyMainService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/ecoStrategy" )
@Tag(description = "ecoStrategy" , name = "能效策略接口" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class EcoStrategyController {

	private final StrategyMainService mainService;
	private final StrategyVariableMapper variableMapper;

	@Operation(summary = "查询策略" , description = "查询策略" )
	@GetMapping("/getStrategy")
	public R getStrategy(String ids){
		List<StrategyMain> strategyMains = mainService.getBaseMapper().selectList(Wrappers.lambdaQuery());
		String allIds = "";
		for (int i = 0; i < strategyMains.size(); i++) {
			allIds += strategyMains.get(i).getId() + ",";
		}
		return R.ok(mainService.getStrategy(allIds));
	}

	@Operation(summary = "策略常量修改" , description = "策略常量修改" )
	@PutMapping("/constUpdate")
	public R constUpdate(){
		return null;
	}

	@Operation(summary = "策略变量修改" , description = "策略变量修改" )
	@PutMapping("/variableUpdate")
	public R variableUpdate(@RequestBody StrategyVariable variable){
		int update = variableMapper.update(Wrappers.<StrategyVariable>lambdaUpdate()
						.eq(StrategyVariable::getId, variable.getId())
						.set(StringUtils.isNotEmpty(variable.getValue()), StrategyVariable::getValue, variable.getValue()));
		return R.ok(update);
	}



}
